package com.example.dou2204.login;

import androidx.lifecycle.MutableLiveData;

import com.example.dou2204.baseMVVM.BaseRepo;
import com.example.dou2204.entity.UserEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

public class LoginRepo extends BaseRepo {
    public void login(RequestBody body, MutableLiveData<UserEntity> success,MutableLiveData<String> fail){
        apiServer.login(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UserEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(UserEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue("请求失败："+e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
